const { Sequelize } = require('sequelize');

const sequelize = new Sequelize({
  dialect: 'mysql',
  host: 'localhost',
  port: 3306,
  username: 'root',
  password: '888mei525',
  database: 'lingxi_system',
  logging: false
});

async function checkTable() {
  try {
    await sequelize.authenticate();
    console.log('数据库连接成功');
    
    // 检查表是否存在
    const [results, metadata] = await sequelize.query("SHOW TABLES LIKE 'incoming_invoices'");
    if (results.length > 0) {
      console.log('incoming_invoices表已存在');
      
      // 显示表结构
      const [structure, meta] = await sequelize.query("DESCRIBE incoming_invoices");
      console.log('表结构:');
      console.log('字段名\t\t\t类型\t\t\t允许空\t键\t默认值\t额外');
      console.log('----\t\t\t----\t\t\t----\t--\t------\t----');
      structure.forEach(row => {
        console.log(`${row.Field}\t\t\t${row.Type}\t\t${row.Null === 'YES' ? 'YES' : 'NO'}\t${row.Key}\t${row.Default || ''}\t${row.Extra || ''}`);
      });
    } else {
      console.log('incoming_invoices表不存在');
    }
  } catch (error) {
    console.error('检查表时出错:', error.message);
  } finally {
    await sequelize.close();
  }
}

checkTable();